import tensorflow as tf

model = tf.keras.models.load_model('my_model.keras') # 用load_model函数可以加载保存好的模型

# 把数据集加载进来
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

# 使用模型进行预测
predictions = model.predict(x_test[5:6])
print(predictions)
# 计算softmax概率
probs = tf.nn.softmax(predictions, axis=1)
print(probs.numpy())

print(tf.reduce_max(probs, axis=1).numpy()) # 输出概率最大的类别

predicted_classes = tf.argmax(probs, axis=1).numpy()

# 输出预测结果
print(predicted_classes)
print(y_test[5:6]) # 输出真实标签
